global !p

from mdtex.scopes import math, pure_math

endglobal

################################################################
#                                                              #
#                            Layout                            #
#                                                              #
################################################################

context "math()"
snippet \\ "换行 Line Break" Ai
\\\\ 
endsnippet

context "math()"
snippet \. "换行 Line Break" Ai
\\\\

endsnippet

context "math()"
snippet "(?<!\\)," "下标 Subscript" r
_{${1:${VISUAL}}}$0
endsnippet

context "pure_math()"
snippet "([a-zA-Z])(\d)" "自动数字下标 Auto Number Subscript" Air
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet

context "math()"
snippet "_(\d\d)" "自动数字下标 Auto Number Subscript" Air
_`!p snip.rv = "{" + match.group(1) + "}"`
endsnippet

context "math()"
snippet "_\{(\d+)\}(\d)" "自动数字下标 Auto Number Subscript" Air
_{`!p snip.rv = match.group(1) + match.group(2)`}
endsnippet

context "math()"
snippet ",([a-zA-Z])" "自动变量下标 Auto Variable Subscript" Air
_`!p snip.rv = match.group(1)`
endsnippet

context "math()"
snippet ",(\d)" "自动数字下标 Auto Number Subscript" Air
_`!p snip.rv = match.group(1)`
endsnippet

context "math()"
snippet ' "上标 Superscript" i
^{${1:${VISUAL}}}$0
endsnippet

context "math()"
snippet "'([\d-])" "数字上标 Number Superscript" Air
^`!p snip.rv = match.group(1)`
endsnippet

context "math()"
snippet "'([a-zA-Z])" "字母上标 Letter Superscript" Air
^`!p snip.rv = match.group(1)`
endsnippet

context "math()"
snippet "\^((?:\d|-)\d)" "自动数字上标 Auto Number Superscript" Air
^`!p snip.rv = "{" + match.group(1) + "}"`
endsnippet

context "math()"
snippet "\^\{(-?\d+)\}(\d)" "自动数字上标 Auto Number Superscript" Air
^{`!p snip.rv = match.group(1) + match.group(2)`}
endsnippet

context "math()"
snippet subst "Substack" w
_{\substack{${1:${VISUAL}}}}$0
endsnippet

context "math()"
snippet smash "Smash" w
\smash[${1|t,b, |}]{${2:${VISUAL}}}$0
endsnippet
